package czk.concrent.threadstatus;

import java.util.concurrent.TimeUnit;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/4/28 23:27
 */
public class Interupt {
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println(123);
                    Thread.sleep(2*1000);
                    System.out.println(456);
                    // 可读性更好，可以替换Thread.sleep
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    System.out.println(789);
                    e.printStackTrace();
                }
            }
        },"t1");
        Thread.sleep(1*1000);
        thread.start();
        // 休眠
        TimeUnit.SECONDS.sleep(1);
        System.out.println(thread.getState());
        // 打断
        thread.interrupt();
        // 运行状态
        System.out.println(thread.getState());
    }
}
